package com.aries.ui.widget.demo.util;

import com.aries.ui.widget.BasisDialog;
import com.aries.ui.helper.navigation.NavigationBarUtil;
import com.aries.ui.helper.navigation.NavigationViewHelper;
import com.aries.ui.util.DrawableUtil;

import com.aries.ui.util.RomUtil;
import com.aries.ui.widget.demo.ResourceTable;
import com.aries.ui.widget.i.NavigationBarControl;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * @Author: AriesHoo on 2019/4/23 14:50
 * @E-Mail: AriesHoo@126.com
 * @Function:
 * @Description:
 */
public class NavigationBarControlUtil {

    public static NavigationBarControl getNavigationBarControl(boolean isNavigation,boolean isNavigationPlus){
        return new NavigationBarControl() {
            @Override
            public boolean setNavigationBar(BasisDialog dialog, NavigationViewHelper helper, Component bottomView) {
//                Element drawableTop = ContextCompat.getDrawable(dialog.get, R.color.colorLineGray);
                Element drawableTop = getColorDrawable(dialog.getContext(), ResourceTable.Color_colorLineGray);

                DrawableUtil.setDrawableWidthHeight(drawableTop, SizeUtil.getScreenWidth(), SizeUtil.dp2px(0.5f));
                helper.setNavigationViewDrawableTop(drawableTop)
                        .setPlusNavigationViewEnable(isNavigationPlus)
                        .setNavigationBarLightMode(true)
                        .setNavigationViewColor(Color.argb(isDialogDarkIcon() ? 0 : 60, 0, 0, 0))
                        .setNavigationLayoutColor(Color.WHITE.getValue());
                //导航栏在底部控制才有意义,不然会很丑;开发者自己决定;这里仅供参考
                return NavigationBarUtil.isNavigationAtBottom(dialog.getContext(),dialog.getWindow()) && isNavigation;
            }
        };
    }


    public static int getColor(Context mContext, int res) {
        int result = 0;
        try {
            result = mContext.getResourceManager().getElement(res).getColor();
        } catch (Exception e) {
        }
        return result;
    }

    public static Element getColorDrawable(Context mContext,int res) {
        int color = getColor(mContext,res);
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(RgbColor.fromArgbInt(color));

        return shapeElement;
    }

    public static boolean isDialogDarkIcon() {
        return (RomUtil.isEMUI() && (RomUtil.getEMUIVersion().compareTo("EmotionUI_4.1") > 0));
    }
}
